import {BASE_URL} from './config'

function request(url, options) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: `${BASE_URL}${url}`,
			method: options.method || 'GET',
			data: options.data || {},
			header: options.headers || {},
			withCredentials: true,
			success: (res) => {
				if (res.statusCode === 200) {
					resolve(res.data);}
				else {
					reject(new Error(res.errMsg));
				}
			},
			fail: (err) => {
				reject(new Error(err.errMsg));
			}
		});
	});
}

module.exports = {
	request: request
}